package lc20240626;

import java.util.Arrays;

public class AddOne {
    public static int[] plusOne(int[] digits) {
        int length = digits.length;
        for (int i = length-1; i >=0; i--) {
            if (digits[i]<9){
                digits[i]++;
                return digits;
            }
            //如果当前位是9
            digits[i]=0;
        }
        //如果所有都进位了
        int[] res=new int[length+1];
        res[0]=1;
        return res;
    }

    public static void main(String[] args) {
        int[] nums={9,9,9};
        int[] arr = plusOne(nums);
        System.out.println(Arrays.toString(arr));
    }
}
